home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Container / Sources / Select.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  24.4 KB  |  819 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Select.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef SELECT_H
  13. #include "Select.h"
  14. #endif
  15.  
  16. #ifndef CONTENT_H
  17. #include "Content.h"
  18. #endif
  19.  
  20. #ifndef PART_H
  21. #include "Part.h"
  22. #endif
  23.  
  24. #ifndef FRAME_H
  25. #include "Frame.h"
  26. #endif
  27.  
  28. #ifndef PROXY_H
  29. #include "Proxy.h"
  30. #endif
  31.  
  32. #ifndef COMMANDS_H
  33. #include "Commands.h"
  34. #endif
  35.  
  36. #ifndef TRACKER_H
  37. #include "Tracker.h"
  38. #endif
  39.  
  40. // ----- Part Layer -----
  41.  
  42. #ifndef FWPRESEN_H
  43. #include "FWPresen.h"
  44. #endif
  45.  
  46. #ifndef FWITERS_H
  47. #include "FWIters.h"
  48. #endif
  49.  
  50. #ifndef FWCONTXT_H
  51. #include "FWContxt.h"
  52. #endif
  53.  
  54. #ifndef FWFCTCLP_H
  55. #include "FWFctClp.h"
  56. #endif
  57.  
  58. // ----- OS Layer -----
  59.  
  60. #ifndef FWODGEOM_H
  61. #include "FWODGeom.h"
  62. #endif
  63.  
  64. #ifndef SLMixOS_H
  65. #include "SLMixOS.h"
  66. #endif
  67.  
  68. // ----- OpenDoc Includes -----
  69.  
  70. #ifndef SOM_ODShape_xh
  71. #include <Shape.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODStorageUnit_xh
  75. #include <StorageU.xh>
  76. #endif
  77.  
  78. #ifndef SOM_Module_OpenDoc_StdProps_defined
  79. #include <StdProps.xh>
  80. #endif
  81.  
  82. //========================================================================================
  83. // Runtime Information
  84. //========================================================================================
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment odfcontainer
  88. #endif
  89.  
  90. //========================================================================================
  91. //    class CContainerSelection
  92. //========================================================================================
  93.  
  94. FW_DEFINE_AUTO(CContainerSelection)
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    CContainerSelection::CContainerSelection
  98. //----------------------------------------------------------------------------------------
  99.  
  100. CContainerSelection::CContainerSelection(Environment* ev, CContainerPart* part):
  101.     FW_CSelection(ev, false, false),    // no linking allowed
  102.     fContainerPart(part),
  103.     fUpdateShape(NULL),
  104.     fCount(0),
  105.     fSelectionContent(NULL),
  106.     fWorkingHandle(FW_kZeroRect, FW_kFill),
  107.     fDraggedContent(NULL)
  108. {
  109.     fSelectionContent = FW_NEW(CSelectionContent, (ev, part, this));
  110.     fWorkingHandle.SetInk(FW_kInvertInk);
  111.     FW_END_CONSTRUCTOR
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    CContainerSelection::~CContainerSelection
  116. //----------------------------------------------------------------------------------------
  117.  
  118. CContainerSelection::~CContainerSelection()
  119. {
  120.     FW_START_DESTRUCTOR
  121.     if (fUpdateShape)
  122.     {
  123.         FW_SOMEnvironment ev;
  124.         fUpdateShape->Release(ev);
  125.     }
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    CContainerSelection::GetSelectedContent
  130. //----------------------------------------------------------------------------------------
  131.  
  132. FW_CContent* CContainerSelection::GetSelectedContent(Environment* ev)
  133. {
  134. FW_UNUSED(ev);
  135.     return fSelectionContent;
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    CContainerSelection::WhichHandle
  140. //----------------------------------------------------------------------------------------
  141.  
  142. CProxy* CContainerSelection::WhichHandle(Environment* ev, 
  143.                                         FW_CGraphicContext& gc, 
  144.                                         const FW_CPoint& mouse, 
  145.                                         short& whichHandle,
  146.                                         FW_Fixed zoomFactor) const
  147. {
  148. FW_UNUSED(ev);
  149.     whichHandle = 0;
  150.     
  151.     if (fCount != 0)
  152.     {
  153.         CContentProxyIterator ite(fSelectionContent);
  154.         for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  155.         {
  156.             whichHandle = proxy->WhichHandle(gc, mouse, zoomFactor);
  157.             if (whichHandle != 0)
  158.                 return proxy;
  159.         }
  160.     }
  161.     
  162.     return NULL;
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. //    CContainerSelection::RenderSelectionHandles
  167. //----------------------------------------------------------------------------------------
  168.  
  169. void CContainerSelection::RenderSelectionHandles(Environment* ev, FW_CGraphicContext& gc, FW_Fixed zoomFactor)
  170. {
  171. FW_UNUSED(ev);
  172.     CContentProxyIterator ite(fSelectionContent);
  173.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  174.     {
  175.         proxy->RenderHandles(gc, zoomFactor);    
  176.     }
  177. }
  178.  
  179. //----------------------------------------------------------------------------------------
  180. //    CContainerSelection::InvalidateSelectionHandles
  181. //----------------------------------------------------------------------------------------
  182.  
  183. void CContainerSelection::InvalidateSelectionHandles(Environment* ev, CContainerFrame* frame)
  184. {
  185.     FW_CSuperView* contentView = frame->GetContentView(ev);
  186.     FW_CAcquiredODShape workingShape1 = FW_NewODShape(ev);
  187.     FW_CAcquiredODShape workingShape2 = FW_NewODShape(ev);
  188.     CContentProxyIterator ite(fSelectionContent);
  189.     FW_Fixed penSize = CalcHandlePenSize(frame->GetZoomFactor());
  190.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  191.     {
  192.         proxy->InvalidateHandles(ev, contentView, workingShape1, workingShape2, penSize);
  193.     }
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    CContainerSelection::RenderAllHandles
  198. //----------------------------------------------------------------------------------------
  199.  
  200. void CContainerSelection::RenderAllHandles(Environment* ev, CContainerFrame* frame)
  201. {
  202.     if (fCount != 0)
  203.     {        
  204.         FW_CFrameFacetIterator ite(ev, frame);
  205.         for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  206.         {
  207.             FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  208.             RenderSelectionHandles(ev, vc, frame->GetZoomFactor());
  209.         }
  210.     }
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    CContainerSelection::RenderHandles
  215. //----------------------------------------------------------------------------------------
  216.  
  217. void CContainerSelection::RenderHandles(Environment* ev, CProxy* proxy)
  218. {
  219.     FW_CPresentationFrameIterator ite(ev, GetPresentation(ev));
  220.     for (CContainerFrame* frame = (CContainerFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (CContainerFrame*)ite.Next(ev))
  221.     {
  222.         if (frame->HasSelectionFocus(ev) && frame->GetWindow(ev)->IsActive(ev))
  223.         {
  224.             
  225.             FW_CFrameFacetIterator i(ev, frame);            
  226.             for (ODFacet* facet = i.First(ev); i.IsNotComplete(ev); facet = i.Next(ev))
  227.             {
  228.                 FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  229.                 proxy->RenderHandles(vc, frame->GetZoomFactor());
  230.             }
  231.         }
  232.     }
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. //    CContainerSelection::CloseSelection
  237. //----------------------------------------------------------------------------------------
  238.  
  239. void CContainerSelection::CloseSelection(Environment* ev)
  240. {
  241.     CProxy* proxy;
  242.     while ((proxy = fSelectionContent->GetFirstProxy()) != NULL)
  243.     {
  244.         DoRemove(ev, proxy);
  245.         RenderHandles(ev, proxy);        // turn off
  246.     }
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250. //    CContainerSelection::AddToSelection
  251. //----------------------------------------------------------------------------------------
  252.  
  253. void CContainerSelection::AddToSelection(Environment* ev, CProxy* theProxy, FW_Boolean renderHandles)
  254. {                
  255.     if (theProxy != NULL)
  256.     {
  257.         DoAdd(ev, theProxy);
  258.         if (renderHandles)
  259.             RenderHandles(ev, theProxy);    // Turn on    
  260.     }        
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. //    CContainerSelection::RemoveFromSelection
  265. //----------------------------------------------------------------------------------------
  266.  
  267. void CContainerSelection::RemoveFromSelection(Environment* ev, CProxy* proxy, FW_Boolean renderHandles)
  268. {                
  269.     if (proxy != NULL)
  270.     {
  271.         DoRemove(ev, proxy);
  272.         if (renderHandles)
  273.             RenderHandles(ev, proxy);        // Turn Off
  274.     }    
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. //    CContainerSelection::DoAdd
  279. //----------------------------------------------------------------------------------------
  280.  
  281. void CContainerSelection::DoAdd(Environment* ev, CProxy* proxy)
  282. {
  283.     fSelectionContent->AddProxy(ev, proxy);
  284.     this->ProxyAdded(ev, proxy);
  285. }
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    CContainerSelection::ProxyAdded
  289. //----------------------------------------------------------------------------------------
  290.  
  291. void CContainerSelection::ProxyAdded(Environment* ev, CProxy* proxy)
  292. {
  293.     proxy->SelectProxy(ev, true);
  294.     fCount++;
  295.     
  296.     ClearCache(ev);
  297. }
  298.  
  299. //----------------------------------------------------------------------------------------
  300. //    CContainerSelection::DoRemove
  301. //----------------------------------------------------------------------------------------
  302.  
  303. void CContainerSelection::DoRemove(Environment* ev, CProxy* proxy)
  304. {
  305.     fSelectionContent->RemoveProxy(ev, proxy);
  306.     proxy->SelectProxy(ev, false);
  307.     fCount--;
  308.     
  309.     ClearCache(ev);
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    CContainerSelection::ClearSelection
  314. //----------------------------------------------------------------------------------------
  315.  
  316. void CContainerSelection::ClearSelection(Environment* ev)
  317. {
  318.     FW_CAcquiredODShape updateShape = GetUpdateShape(ev)->Copy(ev);
  319.     
  320.     CProxy* proxy;
  321.     while ((proxy = fSelectionContent->GetFirstProxy()) != NULL)
  322.     {
  323.         DoRemove(ev, proxy);                        // Remove from selection list
  324.         fContainerPart->DetachProxy(ev, proxy);        // Remove from part
  325.     }
  326.     
  327.     FW_CFacetClipper facetClipper;
  328.     facetClipper.Clip(ev, GetPresentation(ev), updateShape);
  329.     GetPresentation(ev)->Invalidate(ev, updateShape);
  330. }
  331.  
  332. //----------------------------------------------------------------------------------------
  333. //    CContainerSelection::SelectAll
  334. //----------------------------------------------------------------------------------------
  335.  
  336. void CContainerSelection::SelectAll(Environment* ev)
  337. {    
  338.     CContainerFrame* activeFrame = (CContainerFrame*)fContainerPart->GetLastActiveFrame(ev);
  339.     
  340.     RenderAllHandles(ev, activeFrame);
  341.  
  342.     CContentProxyIterator ite(fContainerPart->GetPartContent());
  343.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  344.     {
  345.         if (!proxy->IsSelected())
  346.             DoAdd(ev, proxy);
  347.     }
  348.     
  349.     RenderAllHandles(ev, activeFrame);
  350. }
  351.  
  352. //----------------------------------------------------------------------------------------
  353. //    CContainerSelection::IsEmpty
  354. //----------------------------------------------------------------------------------------
  355.  
  356. FW_Boolean CContainerSelection::IsEmpty(Environment* ev) const
  357. {    
  358. FW_UNUSED(ev);
  359.     return fCount == 0;
  360. }
  361.  
  362. //----------------------------------------------------------------------------------------
  363. //    CContainerSelection::CenterSelection
  364. //----------------------------------------------------------------------------------------
  365.  
  366. FW_CPoint CContainerSelection::CenterSelection(Environment* ev, FW_CFrame* scopeFrame)
  367. {
  368.     FW_ASSERT(scopeFrame);
  369.     
  370.     FW_CRect bounds = scopeFrame->GetContentView(ev)->GetBoundsInContent(ev);
  371.     FW_CRect box(fDragRect);
  372.     box.PlaceInCenterOf(bounds);
  373.             
  374.     FW_CPoint result(box.left - fDragRect.left, box.top - fDragRect.top);
  375.     OffsetSelection(ev, result.x, result.y);
  376.     
  377.     FW_CFacetClipper facetClipper;
  378.     facetClipper.Clip(ev, GetPresentation(ev), GetUpdateShape(ev));    
  379.     GetPresentation(ev)->Invalidate(ev, GetUpdateShape(ev));
  380.  
  381.     return result;
  382. }
  383.  
  384. //----------------------------------------------------------------------------------------
  385. //    CContainerSelection::Resize
  386. //----------------------------------------------------------------------------------------
  387.  
  388. FW_Boolean CContainerSelection::Resize(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  389. {    
  390.     if (fClickedHandle == 0)
  391.         return FALSE;
  392.         
  393.     if (!this->IsOKtoEdit(ev))    // can't resize read only part
  394.     {
  395.         FW_Beep();
  396.         return TRUE;
  397.     }
  398.                 
  399.     if (!theMouseEvent.WaitUntilMouseMoved(ev))
  400.         return TRUE;
  401.     
  402.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  403.     CContainerFrame* frame = (CContainerFrame*)FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  404.  
  405.     CProxy* anchorProxy = GetAnchorProxy();
  406.     
  407.     FW_CInk resizeInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
  408.     FW_CStyle resizeStyle(FW_kFixed0, FW_kGrayPat);
  409.     
  410.     CResizeTracker resizeTracker(ev, frame->GetContentView(ev), facet, anchorProxy, fClickedHandle, resizeInk, resizeStyle);
  411.     if (resizeTracker.Track(ev, theMouseEvent))
  412.     {
  413.         GetPresentation(ev)->Invalidate(ev, GetUpdateShape(ev));
  414.  
  415.         FW_CPoint lastLocation;
  416.         resizeTracker.GetLastLocation(lastLocation);
  417.         FW_CRect srcRect, dstRect;
  418.         anchorProxy->GetMappedRects(fClickedHandle, lastLocation, srcRect, dstRect);
  419.  
  420.         CResizeCommand* cmd = FW_NEW(CResizeCommand,
  421.                                         (ev, fContainerPart, frame, this,
  422.                                          srcRect, dstRect));
  423.         cmd->Execute(ev);
  424.     }
  425.     else
  426.     {
  427.         FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  428.  
  429.         FW_Fixed penSize = CalcHandlePenSize(frame->GetZoomFactor());
  430.         anchorProxy->CalcHandle(fClickedHandle, &fWorkingHandle, penSize);
  431.         fWorkingHandle.Render(vc);    // redraw the handle
  432.     }
  433.     
  434.     return TRUE;
  435. }
  436.  
  437. //----------------------------------------------------------------------------------------
  438. //    CContainerSelection::CalcCache
  439. //----------------------------------------------------------------------------------------
  440.  
  441. void CContainerSelection::CalcCache(Environment* ev)
  442. {
  443.     fDragRect.Clear();
  444.     
  445.     if (fUpdateShape == NULL)
  446.         fUpdateShape = ::FW_NewODShape(ev);
  447.     
  448.     if (fCount == 0)
  449.         return;
  450.     
  451.     FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
  452.     FW_CRect tempRect;
  453.  
  454.     FW_Boolean first = TRUE;
  455.     CContentProxyIterator ite(fSelectionContent);
  456.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  457.     {
  458.         tempRect = proxy->GetBounds(ev);
  459.         proxy->GetUpdateBox(ev, aqTempShape);
  460.         if (first)
  461.         {
  462.             fDragRect = tempRect;
  463.             fUpdateShape->CopyFrom(ev, aqTempShape);
  464.         }
  465.         else
  466.         {
  467.             fDragRect |= tempRect;
  468.             fUpdateShape->Union(ev, aqTempShape);
  469.         }
  470.         proxy->SetHasChanged(FALSE);
  471.                         
  472.         first = FALSE;
  473.     }
  474. }
  475.  
  476. //----------------------------------------------------------------------------------------
  477. //    CContainerSelection::AcquireSelectionShape
  478. //----------------------------------------------------------------------------------------
  479.  
  480. ODShape* CContainerSelection::AcquireSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  481. {
  482. FW_UNUSED(frame);
  483. FW_UNUSED(facet);
  484.  
  485.     return ::FW_NewODShape(ev, fDragRect);
  486. }
  487.  
  488. //----------------------------------------------------------------------------------------
  489. //    CContainerSelection::AcquireSelectionOutline
  490. //----------------------------------------------------------------------------------------
  491.  
  492. ODShape* CContainerSelection::AcquireSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  493. {
  494.     FW_ASSERT(GetAnchorProxy());
  495.     
  496.     FW_CAcquiredODShape outline = GetAnchorProxy()->CreateProxyOutline(ev);
  497.  
  498.     if (fCount > 1)
  499.     {
  500.         FW_CAcquiredODShape shapeOutline = FW_CSelection::AcquireSelectionOutline(ev, facet, frame);
  501.         outline->Union(ev, shapeOutline);
  502.     }
  503.  
  504.     return outline.Orphan();
  505. }
  506.  
  507. //----------------------------------------------------------------------------------------
  508. //    CContainerSelection::OffsetSelection
  509. //----------------------------------------------------------------------------------------
  510.  
  511. void CContainerSelection::OffsetSelection(Environment* ev, FW_Fixed xDelta, FW_Fixed yDelta)
  512. {
  513.     FW_CAcquiredODShape aqUnionShape(GetUpdateShape(ev)->Copy(ev));
  514.     
  515.     CContentProxyIterator ite(fSelectionContent);
  516.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  517.     {
  518.         proxy->OffsetProxy(ev, xDelta, yDelta);
  519.     }
  520.     
  521.     aqUnionShape->Union(ev, GetUpdateShape(ev));
  522.     
  523.     FW_CFacetClipper facetClipper;
  524.     facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
  525. }
  526.  
  527. //----------------------------------------------------------------------------------------
  528. //    CContainerSelection::SelectWithRectangle
  529. //----------------------------------------------------------------------------------------
  530.  
  531. void CContainerSelection::SelectWithRectangle(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  532. {
  533.     FW_CStyle trackStyle(FW_kFixed0, FW_kAntPat);
  534.     FW_CInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
  535.     CTrackRect rectShape(trackInk, trackStyle);    // Create a rect shape on the stack
  536.     
  537.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  538.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  539.  
  540.     CSelectTracker tracker(ev, frame->GetContentView(ev), facet, &rectShape);
  541.     if (tracker.Track(ev, theMouseEvent))
  542.     {
  543.         FW_Boolean isShift = theMouseEvent.IsExtendModifier(ev);
  544.         FW_CRect selectRect;
  545.         rectShape.GetRectBounds(selectRect);
  546.         
  547.         CContentProxyIterator ite(fContainerPart->GetPartContent());
  548.         for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  549.         {
  550.             if (proxy->InSelectionRect(selectRect))
  551.             {
  552.                 if (proxy->IsSelected())
  553.                 {
  554.                     if (isShift)
  555.                     {
  556.                         DoRemove(ev, proxy);
  557.                         RenderHandles(ev, proxy);        // Turn Off
  558.                     }
  559.                 }
  560.                 else
  561.                 {
  562.                     DoAdd(ev, proxy);
  563.                     RenderHandles(ev, proxy);    // Turn on    
  564.                 }
  565.             }
  566.             else if (proxy->IsSelected() && !isShift)
  567.             {
  568.                 DoRemove(ev, proxy);
  569.                 RenderHandles(ev, proxy);        // Turn Off
  570.             }
  571.         }            
  572.     }
  573.     else
  574.     {
  575.         if (!theMouseEvent.IsExtendModifier(ev))
  576.             CloseSelection(ev);
  577.     }
  578. }
  579.  
  580. //----------------------------------------------------------------------------------------
  581. //    CContainerSelection::SelectionChanged
  582. //----------------------------------------------------------------------------------------
  583.  
  584. void CContainerSelection::SelectionChanged(Environment* ev)
  585. {
  586.     //--- Notify frames ---
  587.     GetPresentation(ev)->ContentUpdated(ev);
  588. }
  589.  
  590. //----------------------------------------------------------------------------------------
  591. //    CContainerSelection::IsMouseInDraggableItem
  592. //----------------------------------------------------------------------------------------
  593.  
  594. FW_Boolean CContainerSelection::IsMouseInDraggableItem(Environment* ev, 
  595.                                                   FW_CFrame* frame, 
  596.                                                   const FW_CMouseEvent& theMouseEvent, 
  597.                                                   FW_Boolean inBackground)
  598. {    
  599. FW_UNUSED(inBackground);
  600.     fClickedHandle = 0;
  601.     fAnchorProxy = NULL;
  602.  
  603.     FW_CViewContext vc(ev, frame->GetContentView(ev), theMouseEvent.GetFacet(ev));
  604.  
  605.     // ----- Look first for a handle -----
  606.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  607.     frame->GetContentView(ev)->FrameToViewContent(ev, where);
  608.  
  609.     CProxy* clickedProxy = WhichHandle(ev, vc, where, fClickedHandle, ((CContainerFrame*)frame)->GetZoomFactor());
  610.     if (clickedProxy != NULL)
  611.     {
  612.         fAnchorProxy = clickedProxy;
  613.         return FALSE;            // if in a handle we won't drag
  614.     }
  615.     
  616.     // ----- then look for a selected proxy -----
  617.     CProxy* proxy = fContainerPart->WhichProxy(ev, vc, where, TRUE);
  618.     
  619.     if (proxy != NULL && proxy->IsSelected())
  620.     {
  621.         fAnchorProxy = proxy;
  622.         return TRUE;
  623.     }
  624.     
  625.     return FALSE;
  626. }
  627.  
  628. //----------------------------------------------------------------------------------------
  629. // CContainerSelection::UpdateSelectionOnMouseDown
  630. //----------------------------------------------------------------------------------------
  631.  
  632. void CContainerSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  633.                                             const FW_CMouseEvent& mouseEvent,
  634.                                             ODFacet* embeddedFacet,
  635.                                             FW_Boolean inEmbeddedFrameBorder,
  636.                                             FW_Boolean inBackground)
  637. {
  638.     if (inEmbeddedFrameBorder)
  639.     {
  640.         fClickedHandle = 0;
  641.         fAnchorProxy = NULL;
  642.  
  643.         CProxy* theProxy = (CProxy*)fContainerPart->GetProxy(ev, embeddedFacet->GetFrame(ev));
  644.         FW_ASSERT(theProxy);
  645.         
  646.         if (!theProxy->IsSelected())
  647.             AddToSelection(ev, theProxy, TRUE);
  648.                 
  649.         fAnchorProxy = theProxy;
  650.     }
  651.     else
  652.     {
  653.         ODFacet* facet =  mouseEvent.GetFacet(ev);
  654.         FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  655.         FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  656.         FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  657.         frame->GetContentView(ev)->FrameToViewContent(ev, where);
  658.         
  659.         CProxy* clickedProxy = fContainerPart->WhichProxy(ev, vc, where, FALSE);
  660.         if (clickedProxy)
  661.         {
  662.             if (mouseEvent.IsExtendModifier(ev))
  663.             {
  664.                 if (clickedProxy->IsSelected())
  665.                 {
  666.                     RemoveFromSelection(ev, clickedProxy, !inBackground);
  667.                     if (clickedProxy == fAnchorProxy)
  668.                         fAnchorProxy = NULL;
  669.                 }
  670.                 else
  671.                 {
  672.                     AddToSelection(ev, clickedProxy, !inBackground);
  673.                     fAnchorProxy = clickedProxy;
  674.                 }
  675.             }
  676.             else if (!clickedProxy->IsSelected())
  677.             {
  678.                 fAnchorProxy = clickedProxy;
  679.                 CloseSelection(ev);
  680.                 AddToSelection(ev, clickedProxy, !inBackground);
  681.             }    
  682.         }
  683.     }
  684. }
  685.  
  686. //----------------------------------------------------------------------------------------
  687. //    CContainerSelection::DeleteSelection
  688. //----------------------------------------------------------------------------------------
  689.  
  690. void CContainerSelection::DeleteSelection(Environment* ev)
  691. {
  692.     CProxy* proxy;
  693.     while ((proxy = fSelectionContent->GetFirstProxy()) != NULL)
  694.     {
  695.         DoRemove(ev, proxy);                        // Remove from selection
  696.         fContainerPart->DeleteProxy(ev, proxy);        // delete the proxy
  697.     }
  698. }
  699.  
  700. //----------------------------------------------------------------------------------------
  701. //    CContainerSelection::IsOKtoEdit
  702. //----------------------------------------------------------------------------------------
  703.  
  704. FW_Boolean CContainerSelection::IsOKtoEdit(Environment* ev)
  705. {
  706.     // Check for a read-only part
  707.     if (fContainerPart->IsReadOnly(ev))
  708.         return false;
  709.  
  710.     return true;
  711. }
  712.  
  713. //----------------------------------------------------------------------------------------
  714. //    CContainerSelection::SelectContent
  715. //----------------------------------------------------------------------------------------
  716. void CContainerSelection::SelectContent(Environment* ev, CBaseContent* content)
  717. {
  718.     this->CloseSelection(ev);
  719.  
  720.     CContentProxyIterator it(content);
  721.     for (CProxy* proxy = it.First(); it.IsNotComplete(); proxy = it.Next())
  722.     {
  723.         this->AddToSelection(ev, proxy, TRUE);
  724.     }
  725. }
  726.  
  727. //----------------------------------------------------------------------------------------
  728. //    CContainerSelection::GetSelectionContent
  729. //----------------------------------------------------------------------------------------
  730.  
  731. CBaseContent* CContainerSelection::GetSelectionContent(Environment* ev)
  732. {
  733. FW_UNUSED(ev);
  734.     return fSelectionContent;
  735. }
  736.  
  737. //----------------------------------------------------------------------------------------
  738. //    CContainerSelection::Count
  739. //----------------------------------------------------------------------------------------
  740.  
  741. unsigned long CContainerSelection::Count() const
  742. {
  743.     return fSelectionContent->CountProxies();
  744. }
  745.  
  746. //----------------------------------------------------------------------------------------
  747. //    CContainerSelection::GetFirstSelectedProxy
  748. //----------------------------------------------------------------------------------------
  749.  
  750. CProxy* CContainerSelection::GetFirstSelectedProxy() const
  751. {
  752.     return fSelectionContent->GetFirstProxy();
  753. }
  754.  
  755. //----------------------------------------------------------------------------------------
  756. //    CContainerSelection::IsSelectedShapesChanged
  757. //----------------------------------------------------------------------------------------
  758.  
  759. FW_Boolean CContainerSelection::IsSelectedShapesChanged(Environment *ev) const
  760. {
  761.     CContentProxyIterator ite(fSelectionContent);
  762.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  763.     {
  764.         if (proxy->HasChanged())
  765.         {
  766.             ((CContainerSelection*)this)->ClearCache(ev);
  767.             return TRUE;
  768.         }
  769.     }
  770.     
  771.     return FALSE;
  772. }
  773.  
  774. //----------------------------------------------------------------------------------------
  775. //    CContainerSelection::ClearCache
  776. //----------------------------------------------------------------------------------------
  777.  
  778. void CContainerSelection::ClearCache(Environment *ev)
  779. {
  780.     if (fUpdateShape)
  781.         fUpdateShape->Release(ev);
  782.     fUpdateShape = NULL;
  783. }
  784.  
  785. //----------------------------------------------------------------------------------------
  786. //    CContainerSelection::GetUpdateShape
  787. //----------------------------------------------------------------------------------------
  788.  
  789. ODShape* CContainerSelection::GetUpdateShape(Environment *ev) const
  790. {        
  791.     if (fUpdateShape == NULL || IsSelectedShapesChanged(ev))
  792.         ((CContainerSelection*)this)->CalcCache(ev);
  793.     
  794.     return fUpdateShape;
  795. }
  796.  
  797. //----------------------------------------------------------------------------------------
  798. //    CContainerSelection::GetDragRect
  799. //----------------------------------------------------------------------------------------
  800.  
  801. FW_CRect CContainerSelection::GetDragRect(Environment *ev) const
  802. {        
  803.     if (fUpdateShape == NULL || IsSelectedShapesChanged(ev))
  804.         ((CContainerSelection*)this)->CalcCache(ev);
  805.  
  806.     return fDragRect;
  807. }
  808.  
  809. //----------------------------------------------------------------------------------------
  810. //    CContainerSelection::CanPasteAsLink
  811. //----------------------------------------------------------------------------------------
  812.  
  813. FW_Boolean  CContainerSelection::CanPasteAsLink(Environment*,  ODPasteAsMergeSetting& setting,  ODStorageUnit*)
  814. {
  815.     setting = kODPasteAsEmbedOnly;
  816.     return fAllowLink;
  817. }
  818.  
  819.